package com.zhbit.hibernateDao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.zhbit.DAO.CommentDao;
import com.zhbit.table.Comment;

public class CommentDaoBean implements CommentDao{
	private SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
			return sessionFactory;
		}
		public void setSessionFactory(SessionFactory sessionFactory) {
			this.sessionFactory = sessionFactory;
		}
		
	@Override
	public void addcomment(Comment comment) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().save(comment);
	}
	@Override
	public List<Comment> findAll(int id) {
		// TODO Auto-generated method stub
		String hql="select c.content,c.commenttime,u.headimg,u.username from Comment as c,User as u  where c.userid = u.id and c.shareid=? ORDER BY c.commentid desc";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, id);
		return query.list();
	}

}
